﻿ <%@ WebHandler Language="C#" Class="VendCustHandler" %>

using System;
using System.Web;
using Activity;
using Activity.API;

public class VendCustHandler : BaseHandler
{

    public VendCustHandler()
    {
        //修改请求为post 方式
        base._httpReuqest = base.Context.Request.Form;
    }

    public void GetCondition()
    {
        var handler = new VendCustSalesReportHandler();
        var userIdStr = _httpReuqest["UserID"];
        if (string.IsNullOrEmpty(userIdStr))
        {
            Error("请登录!");
        }
        else
        {
            var userID = Convert.ToInt32(userIdStr);
            var conditon = handler.GetCondition(userID);
            if (conditon == null)
            {
                Error("获取数据异常");
            }
            else
            {
                Success(conditon);
            }
        }
    }

    public void GetVendCustSalesReport()
    {
        var handler = new VendCustSalesReportHandler();
        var vendCustID = _httpReuqest["vendCustID"];
        var startDateStr = _httpReuqest["startDate"];
        var endDateStr = _httpReuqest["endDate"];
        var periodYear = _httpReuqest["periodYear"];
        var seasonID = _httpReuqest["seasonID"];
        var operationAreaID = _httpReuqest["operationAreaID"];
        var shopNature = _httpReuqest["shopNature"];
        var seriesID = _httpReuqest["seriesID"];
        var modelID = _httpReuqest["modelID"];
        var materialID = _httpReuqest["materialID"];
        var pageStr = _httpReuqest["page"];
        var sizeStr = _httpReuqest["size"];
        if (string.IsNullOrEmpty(vendCustID) || string.IsNullOrEmpty(periodYear) ||
            string.IsNullOrEmpty(startDateStr) || string.IsNullOrEmpty(endDateStr) || string.IsNullOrEmpty(pageStr) ||
            string.IsNullOrEmpty(sizeStr))
        {
            Error("请选择必选参数!");
        }
        else
        {
            var startDate = Convert.ToDateTime(startDateStr);
            var endDate = Convert.ToDateTime(endDateStr);
            var page = Convert.ToInt32(pageStr);
            var size = Convert.ToInt32(sizeStr);
            var conditon = handler.GetVendCustSalesReport(vendCustID, startDate, endDate, periodYear, seasonID,
                operationAreaID, shopNature, seriesID, modelID, materialID, page, size);
            if (conditon == null)
            {
                Error("获取数据异常");
            }
            else
            {
                Success(conditon);
            }
        }
    }

    public void ExportVendCustSalesReport()
    {
        var handler = new VendCustSalesReportHandler();
        var vendCustID = _httpReuqest["vendCustID"];
        var startDateStr = _httpReuqest["startDate"];
        var endDateStr = _httpReuqest["endDate"];
        var periodYear = _httpReuqest["periodYear"];
        var seasonID = _httpReuqest["seasonID"];
        var operationAreaID = _httpReuqest["operationAreaID"];
        var shopNature = _httpReuqest["shopNature"];
        var seriesID = _httpReuqest["seriesID"];
        var modelID = _httpReuqest["modelID"];
        var materialID = _httpReuqest["materialID"];
        if (string.IsNullOrEmpty(vendCustID) || string.IsNullOrEmpty(periodYear) ||
            string.IsNullOrEmpty(startDateStr) || string.IsNullOrEmpty(endDateStr))
        {
            Error("请选择必选参数!");
        }
        else
        {
            var startDate = Convert.ToDateTime(startDateStr);
            var endDate = Convert.ToDateTime(endDateStr);
            var ds = handler.ExportVendCustSalesReport(vendCustID, startDate, endDate, periodYear, seasonID,
                operationAreaID, shopNature, seriesID, modelID, materialID);
            if (ds == null)
            {
                Error("获取数据异常");
            }
            else
            {
                var path = NpoiHelper.ExportByWeb("3224", ds, "省份销售明细报表");
                Success(path);
            }
        }
    }

}